package com.cn.kabalifeuser.ui.my.activity;

import com.cn.kabalifeuser.api.Api;
import com.cn.kabalifeuser.base.BasePresenter;
import com.cn.kabalifeuser.callback.CacheCallBack;
import com.cn.kabalifeuser.config.Constants;
import com.cn.kabalifeuser.ui.login.bean.MsgBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * 项目：KaBaLifeUser
 * 包名：com.cn.kabalifeuser.ui.my.activity
 * 类名：UpPhonePresenter
 * 创建时间：2020/11/10 11:11 AM
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
public class UpPhonePresenter extends BasePresenter<UpPhoneView> {
    /**
     * 验证码
     *
     * @param phone
     * @param type
     */
    public void onPhoneCodeData(String phone, int type) {
        OkGo.<MsgBean>post(Api.API_LOGIN_MSG)
                .params("phone", phone)
                .params("type", type)
                .execute(new CacheCallBack<MsgBean>() {
                    @Override
                    public void onSuccess(Response<MsgBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("手机验证码：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onPhoneCodeSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }
    public void onUpUserInfoPHoneData(String token, String phone, String code) {
        OkGo.<MsgBean>post(Api.API_USER_INFO_UP)
                .headers("token", token)
                .params("phone", phone)
                .params("code", code)
                .execute(new CacheCallBack<MsgBean>() {
                    @Override
                    public void onSuccess(Response<MsgBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("修改个人信息：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onUpUserInfoSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());


                    }
                });
    }
}
